<template>
  <div class="app-container">
    <!--工具栏-->
    <div class="head-container">
      <!--通用查询-->
      <queryHeader :dict="dict" :permission="permission" />
      <!--通用编辑-->
      <crudOperation :permission="permission" />
    </div>

    <!--表格渲染-->
    <el-table ref="table" v-loading="crud.loading" :data="crud.data" style="width: 100%;" @selection-change="crud.selectionChangeHandler">
      <!--多选框-->
      <el-table-column type="selection" width="55" />
      <!--展示字段-->
      <el-table-column v-if="columns.visible('rentUserName')" prop="rentUserName" label="租户名称" :show-overflow-tooltip="true" />
      <el-table-column v-if="columns.visible('rentUserPhone')" prop="rentUserPhone" label="租户手机号" :show-overflow-tooltip="true" />
      <el-table-column v-if="columns.visible('depositStatus')" prop="depositStatus" label="押金状态" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          {{ dict.label.status_rent_deposit[scope.row.depositStatus] }}
        </template>
      </el-table-column>
      <el-table-column v-if="columns.visible('depositAmount')" prop="depositAmount" label="押金金额" :show-overflow-tooltip="true" />
      <el-table-column v-if="columns.visible('depositTime')" prop="depositTime" label="押金时间" :show-overflow-tooltip="true" />

      <!--操作-->
      <el-table-column label="操作" width="320px" align="center" fixed="right">
        <template slot-scope="scope">
          <el-button v-if="scope.row.depositStatus === 1" size="mini" type="text" @click="doRentTx(scope.row)">
            退还押金
          </el-button>
          <el-button size="mini" type="text" @click="showOrder(scope.row)">
            订单流水
          </el-button>
          <el-button size="mini" type="text" @click="showPay(scope.row)">
            交易流水
          </el-button>
          <el-button size="mini" type="text" @click="showPush(scope.row)">
            推送记录
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!--分页组件-->
    <pagination />

    <!--表单渲染-->
    <editForm :dict="dict" />
  </div>
</template>

<script>
import crudRentUser from '@/api/business/bed/rentuser'
import queryHeader from './module/queryHeader'
import editForm from './module/editForm'
import CRUD, { presenter } from '@crud/crud'
import crudOperation from '@crud/CRUD.operation'
import pagination from '@crud/Pagination'
import { doTx } from '@/api/business/bed/pay'

// crud交由presenter持有
const crud = CRUD({ title: 't_rent_user', url: 'rent/user/list/page/token', crudMethod: { ...crudRentUser }, pkIdName: 'rentUserId' })

export default {
  name: 'RentUser',
  components: { queryHeader, editForm, crudOperation, pagination },
  dicts: ['status_rent_deposit'],
  mixins: [presenter(crud)],
  data() {
    return {
      // 对应几个按钮操作
      permission: {
        add: [],
        edit: [],
        del: []
      }
    }
  },
  created() {
    this.crud.optShow = { add: false, edit: false, del: false, download: true }
  },
  methods: {
    doRentTx(row) {
      doTx(row.rentUserId).then(() => {
        this.$notify({ title: '操作成功', type: 'success', duration: 2500 })
        this.crud.toQuery()
      })
    },
    showOrder(row) {
      this.$router.push({ path: '/order/list', query: { rentUserId: row.rentUserId }})
    },
    showPay(row) {
      this.$router.push({ path: '/pay/list', query: { rentUserId: row.rentUserId }})
    },
    showPush(row) {
      this.$router.push({ path: '/push/list', query: { rentUserId: row.rentUserId }})
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
  /deep/ .el-input-number .el-input__inner {
    text-align: left;
  }
</style>
